.text

__start:
	addi r1, r0, query
	push r1
	pushi 1
	syscall
	addi sp, sp, 8

	pushi 2
	syscall
	addi sp, sp, 4

	push rv
	call fat
	addi sp, sp, 4

	addi r1, r0, label
	push r1
	pushi 1
	syscall
	addi sp, sp, 8

	push rv
	pushi 0
	syscall
	addi sp, sp, 8

	addiu r1, r0, nl
	push r1
	pushi 1
	syscall
	addi sp, sp, 8

	stop

fat:
	push bp
	add bp, sp, r0

	lw r1, bp, 8
	addi r2, r0, 1
	cmp r2, r1
	jeq ret_normal
	addi r2, r1, -1
	push r1
	push r2
	call fat
	addi sp, sp, 4
	pop r1

	mult rv, r1, rv

	jmp epilogue

ret_normal:
	addi rv, r1, 0

epilogue:
	add sp, bp, r0
	pop bp

	ret

.data
	label:	"Resultado = "
	query:	"Digite o numero para calcular o fatorial: "
	nl:		"\n"
